e5c3b6
@@ -31,6 +31,7 @@
 import org.apache.hadoop.hive.serde2.lazy.LazyLong;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
 import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.io.BytesWritable;
 import org.apache.hadoop.io.Text;
 
 /**
@@ -419,7 +420,13 @@
public Text convert(Object input) {
             .getPrimitiveWritableObject(input).toString());
         return t;
       case BINARY:
-        t.set(((BinaryObjectInspector) inputOI).getPrimitiveWritableObject(input).getBytes());
+        BinaryObjectInspector binaryOI = (BinaryObjectInspector) inputOI;
+        if (binaryOI.preferWritable()) {
+          BytesWritable bytes = binaryOI.getPrimitiveWritableObject(input);
+          t.set(bytes.getBytes(), 0, bytes.getLength());
+        } else {
+          t.set(binaryOI.getPrimitiveJavaObject(input));
+        }
         return t;
       case DECIMAL:
         t.set(((HiveDecimalObjectInspector) inputOI).getPrimitiveWritableObject(input).toString());
